package com.longge;

import java.util.Arrays;

public class SuccessfulPairs {

    //spells符咒
    //positions魔力
    public int[] successfulPairs(int[] spells, int[] potions, long success) {
        int[] ans = new int[spells.length];
        Arrays.sort(potions);
        for (int i = 0; i < spells.length; i++) {
            ans[i] = computeCount(spells[i], potions, success);
        }
        return ans;
    }

    private int computeCount(int spell, int[] potions, long success) {
        int left = 0, right = potions.length;

        while (left < right) {
            int mid = left + (right - left) / 2;
            if ((long) potions[mid] * spell >= success) {
                right = mid;
            } else if ((long) potions[mid] * spell < success) {
                left = mid + 1;
            }
        }
        return potions.length - left;
    }



}
